package com.example.demo.service;

import com.example.demo.common.domain.Horder;
import com.example.demo.common.domain.HorderExample;
import com.example.demo.common.domain.Hotel;
import com.example.demo.common.domain.HotelExample;
import com.example.demo.mapper.HorderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service
public class OrderMgService {
    @Autowired
    private HorderMapper horderMapper;
    @Autowired
    private HorderExample horderExample;

    public List<Horder> queryAllHorder(){
        horderExample.createCriteria();
        List<Horder> horderList=horderMapper.selectByExample(horderExample);
        horderExample.clear();
        return horderList;
    }
    public String deleteByOrdernames(String[] OrderNamelist ){
        List<String> collection = Arrays.asList(OrderNamelist);

        horderExample.createCriteria().andOrderNumberIn(collection);
        horderMapper.deleteByExample(horderExample);
        horderExample.clear();
        return  "删除完成";
    }

    public List<Horder> queryOrderByTerm(Horder horder) {
        String Ordernumber=horder.getOrderNumber();
        String Rname=horder.getRname();
        String Hotelname=horder.getHotelName();

        Boolean falgO=!(Ordernumber.isEmpty()||Ordernumber==null||Ordernumber.equals("请输入你需要查询的订单号"));
        Boolean falgR=!(Rname.isEmpty()||Rname==null||Rname.equals("请输入你需要查询的真实姓名"));
        Boolean falgH=!(Hotelname.isEmpty()||Hotelname==null||Hotelname.equals("请输入你需要查询的入住酒店"));
        System.out.println("O:"+falgO+",P:"+falgR+",H:"+falgH);
        if (falgO&&falgR&&falgH){  horderExample.createCriteria().andOrderNumberLike("%"+Ordernumber+"%").andRnameLike("%"+Rname+"%").andHotelNameLike("%"+Hotelname+"%");}
        if(falgO==true&&falgR==false&&falgH==false){ horderExample.createCriteria().andOrderNumberLike("%"+Ordernumber+"%");}
        if(falgO==false&&falgR==true&&falgH==false){horderExample.createCriteria().andRnameLike("%"+Rname+"%");}
        if(falgO==false&&falgR==false&&falgH==true){horderExample.createCriteria().andHotelNameLike("%"+Hotelname+"%");}
        if(falgO==true&&falgR==true&&falgH==false){horderExample.createCriteria().andOrderNumberLike("%"+Ordernumber+"%").andRnameLike("%"+Rname+"%");}
        if(falgO==false&&falgR==true&&falgH==true){horderExample.createCriteria().andRnameLike("%"+Rname+"%").andHotelNameLike("%"+Hotelname+"%");}
        if(falgO==true&&falgR==false&&falgH==true){horderExample.createCriteria().andOrderNumberLike("%"+Ordernumber+"%").andHotelNameLike("%"+Hotelname+"%");}
        if(falgH==false&&falgR==false&&falgO==false){horderExample.createCriteria();}
        List<Horder> OrderList= horderMapper.selectByExample(horderExample);
        horderExample.clear();
        return OrderList;
    }
    public String updateState(Horder horder){
        horderMapper.updateByPrimaryKeySelective(horder);
        return  "更新成功";
    }
    public String deleteByOrdername(String OrderNumber){
        horderMapper.deleteByPrimaryKey(OrderNumber);
        return "删除完成";
    }
}
